package com.lichuandi.springbootdemo1.controller;

import com.lichuandi.springbootdemo1.entity.User;
import org.springframework.web.bind.annotation.*;

// Spring Boot 控制器
@RestController
@RequestMapping("/api")
public class PythonController {

    @GetMapping("/hello")
    public String hello(@RequestParam String name) {
        return "Hello, " + name + " from Java!";
    }

    @PostMapping("/user")
    public User createUser(@RequestBody User user) {
        user.setId(1);
        return user; // 返回包含ID的User对象
    }
}
//import requests
//import json
//
//# 1. GET 请求（带参数）
//response = requests.get(
//    "http://localhost:9010/api/hello",
//    params={"name": "Python"}  # 等价于 ?name=Python
//)
//print("GET 响应:", response.text)  # 输出: "Hello, Python from Java!"
//
//# 2. POST 请求（JSON Body）
//user_data = {"name": "Alice"}
//headers = {"Content-Type": "application/json"}
//
//response = requests.post(
//    "http://localhost:9010/api/user",
//    data=json.dumps(user_data),  # 将字典转为JSON字符串
//    headers=headers
//)
//print("POST 响应:", response.json())  # 输出: {"id": 1, "name": "Alice"}